MacShell is a Unix-like command line interface for the Macintosh. It performs a limited impersonation of the Unix C shell, and contains abbreviated versions of a set of Unix style file management, file finding, and content searching utilities. It also does a few Macintosh-specific functions, is scriptable, and has a no-frills text editor built-in.
MacShell is free, courtesy of Fred Videon. It may not be sold in any form.
THE SHELL
The "Shell" component of the program has the following capabilities:
-Executes a set of built-in utilities.
-Executes code resources from external resource files.
-Performs file name substitution. (known to some as "globbing")
-Handles pipes.
-Performs redirection of standard I/O to and from files using the operators ">" and "<".
-Manages shell variables.
-Runs scripts.
Among the many "shell" functions which MacShell does not support are the following:
-Flow control operators
-Launching of other applications
-Command history
-Alias substitutions
-Backquote substitution
BUILT-IN UTILITIES
This version performs approximations of the Unix utilities in the following list.
Note: to get more help with any command, type:
man commandname
command description
------- -----------
man get help
cd change directory
pwd print working directory
ls list the contents of a directory
cat concatenate (spit the input to the output)
head copy the beginning of the input to the output
tail copy the end of the input to the output
cp copy files and directories
mv move or rename files and directories
rm remove files and directories
mkdir make directory
grep file content search
egrep file content search using regular expressions
find find a file or directory by name or attribute
more view a file
exit quit MacShell
Additionally MacShell approximates some utilities which are built in to the Unix C shell:
set set a shell variable
unset clear, or unset a shell variable
echo report command line arguments on the output.
source execute a file as a script
Finally, MacShell has a few special non Unix-like functions:
mem show heap statistics
free show free heap space
compact compact heap and report largest contiguous block
seg filter to segment long lines into shorter lines
xn filter out null characters from a stream
chtype change a Macintosh file type signature
chcreator change a Macintosh file creator signature
bintohex convert input to hexidecimal notation
DETAILS OF SHELL FUNCTIONS
The following "shell" functionality is supported by MacShell:
FILE NAME SUBSTITUTION
If MacShell finds the asterisk (*) in a command argument, it will attempt to substitute any string of characters (including the null string) in place of the asterisk to form one or more valid file names. This name (or these names) will be substituted into the command string prior to the execution of the command. Correct case must be observed when this mechanism is used. (Otherwise the Macintosh is case-insensitive.)
An asterisk may be hidden from MacShell by surrounding the argument that contains it in either double ("") or single ('') quotes. The argument will then be passed on to its command unaltered.
PIPE HANDLING
MacShell allows the output of one of its commands to be directed to the input of another by means of a pipe. The pipe character (|) is used to separate the two commands. (Note that MacShell's internal implementation of the pipe is quite different from the Unix implementation, even though they behave very similiarly)
REDIRECTION OF COMMAND INPUT AND OUTPUT TO AND FROM FILES
MacShell supports the use of I/O redirection operators "<" and ">." A filename which follows the input redirection symbol (<) on the command line will be opened and its contents will be used as input for the command. A filename which follows the output redirection operator (>) will be created if it does not exist (and overwritten if it does exist), and the output of the command will be written to it.
SHELL VARIABLES
MacShell is capable of managing shell variables. Shell variables are set and cleared with "set" and "unset." (See separate manual entries for set and unset). Set is also useful for displaying a list of currently defined variables and their values.
Once a shell variable is defined it's value may be used by the variable substitution mechanism to form part of a command line. Variable substitution is triggered by a '$' immediately preceeding the variable name. Variable substitution takes place before file name substitution. The entire variable (including the index, if used) may be surrounded by curly braces '{}' to avoid ambiguity if the name does not form a separate argument.
A shell variable may take a value of zero or more words. If the value consists of more than one word, the individual words may be selected by means of an index value in square brackets immediately following the variable name. The index value itself may be a shell variable since the variable substitution mechanism will evaluate index values first. Index values begin at 1. Supplying an index value of zero generates an error.
Special designators "$#" and "$?" can be used immediatly preceeding a shell variable name to cause the substitution mechanism to insert other information about shell variables. "$#varname" will be replaced with the number of words in the value of "varname," while "$?varname" will be replaced with "1" if the variable is set, and "0" otherwise.
SHELL VARIABLE EXAMPLES
Shell variables may be set in any of the following ways:
set a=1
set b=abc
set c
set d=()
set e=(1 2 3)
set e[1]=4
Some simple examples using the shell utility "echo" to report the results of variable substitution with the variables defined above:
echo $a
1
echo $e
(4 2 3)
echo $e[2]
2
echo $e[$a]
4
echo I'm${e[$a]}it
I'm4it
echo $#e
3
echo $?b
1
echo he's $?{b}for fun
he's 1for fun
echo $?z
0
SCRIPTS
MacShell includes a built-in utilitiy which will open a file and execute each line as a MacShell command. No control flow operators are supported at this time. (For more information see the manual entry for "source"). In addition MacShell can execute certain files at launch time. For more information, see the headings "startup files" and "configuration file" in this entry.
STANDARD INPUT AND STANDARD OUTPUT
Standard input and output is a means by which many Unix utilities interact with the outside world. MacShell supports this paradigm to some extent.
Standard input may be directed to some MacShell commands from a file with the input redirection operator (<), or from the output of the preceeding command using a pipe (|). MacShell cannot use the interactive window as standard input at this time.
The default standard output for most MacShell commands is the interactive window. If the pipe operator (|) is used, standard output is routed to the command which follows. If the output redirection operator (>) is present, standard output is directed to the file whose name follows the operator.
ABOUT MACINTOSH PATH NAMES
According to Macintosh convention, the colon (:) is used in path names to separate volume, folder and file names. The following rules should be noted:
-Absolute path names do not begin with a colon, for example:
MyDisk:MyFolder:MyFile
-When an absolute path name consists of only one name, it must end in a colon, for example:
MyDisk:
-Relative path names must begin with a colon, except in the case where they consist of only one name:
MyFolder
:MyFolder:MyFile
-Consecutive colons may be used in a path name to represent a move up the directory tree. Two colons (::) would represent the parent of the working directory, three would represent the parent of the parent, and so on.
CASE SENSITIVITY
The Macintosh finder and toolbox are not case sensitive. In other words, as far as the Macintosh is concerned, "Filename" is the same as "filename." Therefore it is not necessary to observe case when using MacShell to interface directly with the Macintosh file system.
However, MacShell's file name substitution function IS case sensitive. If asterisks are used as wildcard characters in file names, case must be observed in the remainder of the name (this should be changed).
ESCAPE NAME COMPLETION
When used interactively MacShell will attempt to complete a file name when the escape key is typed. The user must first type enough characters to form a unique beginning of a file name. The mechanism will add characters until a point of ambiguity is reached, or until the file name is completed. If the file name is not completed, the mechanism will cause a system beep.
Since Macintosh file names may include embedded spaces, and since these names must be quoted in MacShell, the name completion function will ignore a quote found at the beginning of a word. This will allow most file names with embedded spaces to be quoted and automatically completed with ease.
The wildcard character "*" is not recognized by the file name completion mechanism.
Those using older keyboards which don't have the escape key may trigger this function by first setting a special shell variable called "remapesc". This will cause the backquote in the upper left corner of the old Mac Plus keyboard to be interpreted as the escape key.
STARTUP FILES
MacShell treats its startup files just as most other applications do: The files are opened immediately after MacShell is launched. However, it is also possible to cause MacShell to treat startup files as scripts to be executed. A MacShell file will be executed on startup if the first two characters in the file are "#!".(This string is referred to as the Magic Cookie).
Note that a file with the magic cookie will not be executed when it is opened from the File menu, or dealt with by MacShell in most other ways.
CONFIGURATION FILE
If a file called "macshell.rc" is found in the same directory with the MacShell application itself, this file will be opened and executed as a script when MacShell is launched.
INVOKING EXTERNAL CODE RESOURCES FROM MACSHELL
It's possible to write code in a language like C or Pascal, and compile it into code resources which can be called directly by MacShell. Let me know if you want more details. I have some sample code (in C) demonstrating how to do this.